package com.cmo.rzl.calling;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.beetl.sql.core.kit.StringKit;

import com.cmo.rzl.core.base.BaseController;
import com.cmo.rzl.core.jfinal.ext.autoroute.ControllerBind;
import com.cmo.rzl.core.toolbox.Record;
import com.cmo.rzl.core.toolbox.kit.ShardKit;
import com.cmo.rzl.shine.model.Doctor;
import com.cmo.rzl.shine.service.DoctorService;
import com.cmo.rzl.shine.service.QueueTypeService;
import com.cmo.rzl.shine.service.TriageService;
import com.cmo.rzl.shine.service.impl.DoctorServiceImpl;
import com.cmo.rzl.shine.service.impl.QueueTypeServiceImpl;
import com.cmo.rzl.shine.service.impl.TriageServiceImpl;

@ControllerBind(controllerKey="/callqueueType")
public class CallingQueueTypeController extends BaseController {

	DoctorService doctor=new DoctorServiceImpl();
	QueueTypeService service=new QueueTypeServiceImpl();
	TriageService triage = new TriageServiceImpl();
	ShardKit shard=new ShardKit();
	
	//当前登陆医生的队列列表
	public void list_doctor_queuetype(){
		Map<String, Object> map=new HashMap<String, Object>();
		String login_id=getPara("login_id");
		if(StringKit.isBlank(login_id)){
			map.put("return_code", "fail");
			map.put("return_msg", "医生工号不能为空");
			renderJson(map);
			return;
		}
		// 分诊台分诊模式 triage_type 1按医生 2按叫号器
		// 根据医生工号查询分诊台分诊模式
		Record rt = triage.findtypelogin_id(login_id);
		if (null == rt) {
			map.put("return_code", "fail");
			map.put("return_msg", "查询分诊台分诊模式失败");
			renderJson(map);
			return;
		}
		// 获取分诊台分针模式
		String type = rt.get("triage_type").toString();
		if("1".equals(type)){
			Doctor record=doctor.findByLogin_id(login_id);
			if(null==record){
				map.put("return_code", "fail");
				map.put("return_msg", "医生工号不正确");
				renderJson(map);
				return;
			}
			List<Record> list= service.list_doctor_queuetype(login_id);
			if(list.size()<1){
				map.put("return_code", "fail");
				map.put("return_msg", "医生没有队列");
				renderJson(map);
				return;
			}else{
				map.put("return_code", "success");
				map.put("return_msg", "查询成功");
				map.put("count", list.size());
				map.put("list", list);
				renderJson(map);
			}
		}else{
			Doctor record=doctor.findByLogin_id(login_id);
			if(null==record){
				map.put("return_code", "fail");
				map.put("return_msg", "医生工号不正确");
				renderJson(map);
				return;
			}
			List<Record> list= service.list_pager_queuetype(login_id,shard.getIpAddr(getRequest()));
			if(list.size()<1){
				map.put("return_code", "fail");
				map.put("return_msg", "医生没有队列");
				renderJson(map);
				return;
			}else{
				map.put("return_code", "success");
				map.put("return_msg", "查询成功");
				map.put("count", list.size());
				map.put("list", list);
				renderJson(map);
			}
		}
		
	}
}
